﻿using IOP.Orleans.MessageHub;
using Microsoft.Extensions.DependencyInjection;
using Orleans;
using System;

namespace IOP.Orleans.Service.MessageHub
{
    /// <summary>
    /// 消息服务客户端扩展
    /// </summary>
    public static class MessageHubClientExtensions
    {
        /// <summary>
        /// 添加消息总线服务
        /// </summary>
        /// <param name="builder"></param>
        /// <returns></returns>
        public static IOrleansServiceBuilder AddMessageHubService(this IOrleansServiceBuilder builder, Action<MessageHubServiceOption> serviceOption = null)
        {
            builder.ClientBuilder.ConfigureApplicationParts(config =>
            {
                config.AddApplicationPart(typeof(IMessageHubService).Assembly).WithReferences();
            });
            builder.Services.AddOptions<MessageHubServiceOption>();
            if (serviceOption == null) serviceOption = (o) => { };
            builder.Services.Configure(serviceOption);
            builder.Services.AddSingleton<IMessageHubService,MessageHubService>();
            return builder;
        }
    }
}
